//using System;
//using System.Collections.Generic;
//using Brouteforce.Map;
//using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Content;
//using Microsoft.Xna.Framework.Graphics;
//using Microsoft.Xna.Framework.Input;
//using Brouteforce.Characters;

//namespace Brouteforce.NewManagers {
//    /// <summary>
//    /// This is the main type for your game
//    /// </summary>
//    public class MapManager : Manager {

//        public static MapManager Instance = new MapManager();

//        TileMap myMap;
//        int squaresAcross = 22;
//        int squaresDown = 48;
//        int baseOffsetX = -32;
//        int baseOffsetY = -64;
//        float heightRowDepthMod = 0.00001f;
//        SpriteFont pericles6;
//        Texture2D hilight;
//        Texture2D selectionTexture;

//        public override void LoadContent(ContentManager content) {

//            hilight = content.Load<Texture2D>(@"Textures\TileSets\hilight");
//            selectionTexture = content.Load<Texture2D>(@"Textures\TileSets\selection");

//            Tile.TileSetTexture = content.Load<Texture2D>(@"Textures\TileSets\part4_tileset");

//            pericles6 = content.Load<SpriteFont>(@"Fonts\Pericles6");

//            myMap = new TileMap(
//                           content.Load<Texture2D>(@"Textures\TileSets\mousemap"),
//                           content.Load<Texture2D>(@"Textures\TileSets\part9_slopemaps"));

//            Camera.ViewWidth = BFGame.Graphics.PreferredBackBufferWidth;
//            Camera.ViewHeight = BFGame.Graphics.PreferredBackBufferHeight;
//            Camera.WorldWidth = ((myMap.MapWidth - 2) * Tile.TileStepX);
//            Camera.WorldHeight = ((myMap.MapHeight - 2) * Tile.TileStepY);
//            Camera.DisplayOffset = new Vector2(baseOffsetX, baseOffsetY);

//            //myMap.Lowlight();
//        }

//        protected override void _Update(GameTime gameTime, BFGame game) {
//            KeyboardState ks = Keyboard.GetState();
//            if (ks.IsKeyDown(Keys.Up)) Camera.Move(new Vector2(0, -5));
//            if (ks.IsKeyDown(Keys.Down)) Camera.Move(new Vector2(0, 5));
//            if (ks.IsKeyDown(Keys.Left)) Camera.Move(new Vector2(-5, 0));
//            if (ks.IsKeyDown(Keys.Right)) Camera.Move(new Vector2(5, 0));

//            if (InputManager.Instance.MouseClicked.IsChangedSince(UpdateLoopIndex)) {
//                Vector2 pos = new Vector2(InputManager.Instance.CurMouseX, InputManager.Instance.CurMouseY);
//                pos = Camera.ScreenToWorld(pos);
//                Point mcelp = myMap.WorldToMapCell(pos);
//                if (PlayersManager.Instance.Selected != null) {
//                    myMap.HighlightShootRange(mcelp.X, mcelp.Y, Color.Red, 5, PlayersManager.Instance.Selected);
//                }
//            }
//        }

//        /// <summary>
//        /// This is called when the game should draw itself.
//        /// </summary>
//        /// <param name="gameTime">Provides a snapshot of timing values.</param>
//        public override void Draw(GameTime gameTime, BFGame game) {

//            Vector2 firstSquare = new Vector2(Camera.Location.X / Tile.TileStepX, Camera.Location.Y / Tile.TileStepY);
//            int firstX = (int)firstSquare.X;
//            int firstY = (int)firstSquare.Y;

//            Vector2 squareOffset = new Vector2(Camera.Location.X % Tile.TileStepX, Camera.Location.Y % Tile.TileStepY);
//            int offsetX = (int)squareOffset.X;
//            int offsetY = (int)squareOffset.Y;

//            float maxdepth = ((myMap.MapWidth + 1) * ((myMap.MapHeight + 1) * Tile.TileWidth)) / 10;
//            float depthOffset;


//            for (int y = 0; y < squaresDown; y++) {
//                int rowOffset = 0;
//                if ((firstY + y) % 2 == 1)
//                    rowOffset = Tile.OddRowXOffset;

//                for (int x = 0; x < squaresAcross; x++) {
//                    int mapx = (firstX + x);
//                    int mapy = (firstY + y);
//                    depthOffset = 0.7f - ((mapx + (mapy * Tile.TileWidth)) / maxdepth);

//                    if ((mapx >= myMap.MapWidth) || (mapy >= myMap.MapHeight))
//                        continue;

//                   //draw base tiles
//                    foreach (int tileID in myMap.Rows[mapy].Columns[mapx].BaseTiles) {
//                        BFGame.SpriteBatch.Draw(
//                            Tile.TileSetTexture,
//                            Camera.WorldToScreen(
//                                new Vector2((mapx * Tile.TileStepX) + rowOffset, mapy * Tile.TileStepY)),
//                            Tile.GetSourceRectangle(tileID),
//                            Color.White,
//                            0.0f,
//                            Vector2.Zero,
//                            1.0f,
//                            SpriteEffects.None,
//                            1.0f);
//                    }
//                    int heightRow = 0;

//                    //draw hight tiles
//                    foreach (int tileID in myMap.Rows[mapy].Columns[mapx].HeightTiles) {
//                        BFGame.SpriteBatch.Draw(
//                            Tile.TileSetTexture,
//                            Camera.WorldToScreen(
//                                new Vector2(
//                                    (mapx * Tile.TileStepX) + rowOffset,
//                                    mapy * Tile.TileStepY - (heightRow * Tile.HeightTileOffset))),
//                            Tile.GetSourceRectangle(tileID),
//                            Color.White,
//                            0.0f,
//                            Vector2.Zero,
//                            1.0f,
//                            SpriteEffects.None,
//                            depthOffset - ((float)heightRow * heightRowDepthMod));
//                        heightRow++;
//                    }

//                    //draw topper tiles
//                    foreach (int tileID in myMap.Rows[y + firstY].Columns[x + firstX].TopperTiles) {
//                        BFGame.SpriteBatch.Draw(
//                            Tile.TileSetTexture,
//                            Camera.WorldToScreen(
//                                new Vector2((mapx * Tile.TileStepX) + rowOffset, mapy * Tile.TileStepY)),
//                            Tile.GetSourceRectangle(tileID),
//                            Color.White,
//                            0.0f,
//                            Vector2.Zero,
//                            1.0f,
//                            SpriteEffects.None,
//                            depthOffset - ((float)heightRow * heightRowDepthMod));
//                    }

//                    //update vlads row depth
//                    myMap.Rows[mapy].Columns[mapx].CharactersInCell.ForEach(vlad => vlad.DrawDepth = depthOffset - (float)(heightRow + 2) * heightRowDepthMod);

//                    //put highlight on the cell if it need to be there
//                    if (myMap.Rows[mapy].Columns[mapx].Highlighted != null) {
//                        DrawHighlightAt(new Point(mapx, mapy), hilight);
//                    }

//                    //draw position of tiles for debug reason
//                    BFGame.SpriteBatch.DrawString(pericles6, (x + firstX).ToString() + ", " + (y + firstY).ToString(),
//                        new Vector2((x * Tile.TileStepX) - offsetX + rowOffset + baseOffsetX + 24,
//                            (y * Tile.TileStepY) - offsetY + baseOffsetY + 48), Color.White, 0f, Vector2.Zero,
//                            1.0f, SpriteEffects.None, 0.0f);
//                }
//            }

//            //draw highlight under mouse
//            Vector2 hilightLoc = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
//            Point hilightPoint = myMap.WorldToMapCell(new Point((int)hilightLoc.X, (int)hilightLoc.Y));
//            DrawHighlightAt(hilightPoint, hilight);

//            BFGame.SpriteBatch.DrawString(pericles6, "mouse world over: " + hilightLoc, new Vector2(400, 0), Color.White);

//            //draw characters - should not be all charecters - only the ones in the visible area of the map!! (FIX IT LATER)
//            foreach (var c in myMap.CharactersInMap) {

//                int charY =  -myMap.GetOverallHeight(c.PositionInWorld);
//                BFGame.SpriteBatch.Draw(c.Texture,
//                    Camera.WorldToScreen(c.PositionInWorld) + c.DrawOffset + new Vector2(-4, charY+2),
//                    c.Texture.Bounds, Color.White,
//                    0, Vector2.Zero, 0.6f, SpriteEffects.None, c.DrawDepth);

//                //draw selection rectengle
//                if (c.Selected) {
//                    Point selectionPoint = myMap.WorldToMapCell(new Point((int)c.PositionInWorld.X, (int)c.PositionInWorld.Y));
//                    BFGame.SpriteBatch.DrawString(pericles6, "position: " + selectionPoint, new Vector2(200, 0), Color.White);
//                    DrawHighlightAt(selectionPoint, selectionTexture);
//                }
//            }

//            //draw events
//            //foreach (var c in myMap.CharactersInMap) {

//            //    int charY = -myMap.GetOverallHeight(c.PositionInWorld);
//            //    BFGame.SpriteBatch.Draw(c.Texture,
//            //        Camera.WorldToScreen(c.PositionInWorld) + c.DrawOffset + new Vector2(-4, charY + 2),
//            //        c.Texture.Bounds, Color.White,
//            //        0, Vector2.Zero, 0.6f, SpriteEffects.None, c.DrawDepth);

//            //    //draw selection rectengle
//            //    if (c.Selected) {
//            //        Point selectionPoint = myMap.WorldToMapCell(new Point((int)c.PositionInWorld.X, (int)c.PositionInWorld.Y));
//            //        BFGame.SpriteBatch.DrawString(pericles6, "position: " + selectionPoint, new Vector2(200, 0), Color.White);
//            //        DrawHighlightAt(selectionPoint, selectionTexture);
//            //    }
//            //}

//        }

//        //private void DrawOnTopOfMap(Vector2 worldPosition, 

//        public  Vector2 WorldLocationOfCellUnderMouse {
//            get {
//                Vector2 hilightLoc = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
//                Point p = myMap.WorldToMapCell(new Point((int)hilightLoc.X, (int)hilightLoc.Y));

//                Console.WriteLine("World Cell Under Mouse: " + p);

//                //Vector2 hilightLoc = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
//                //Point p = myMap.WorldToMapCell(new Point((int)hilightLoc.X, (int)hilightLoc.Y));
//                int rowOffset = 0;
//                if ((p.Y) % 2 == 1)
//                    rowOffset = Tile.OddRowXOffset;
//                var ret =  new Vector2((p.X * Tile.TileStepX) + rowOffset + 32, (p.Y + 2)  * Tile.TileStepY + 8);
//                Console.WriteLine("World Position of Cell Is: " + ret);
//                return ret;
//            }
//        }


//        public List<Character> CharactersInCellUnderMouse {
//            get {
//                Vector2 hilightLoc = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y));
//                Point p = myMap.WorldToMapCell(new Point((int)hilightLoc.X, (int)hilightLoc.Y));
//                return myMap.Rows[p.Y].Columns[p.X].CharactersInCell;
//            }
//        }


//        private void DrawHighlightAt(Point mapCell, Texture2D hlt) {
//            int hilightrowOffset = 0;
//            if ((mapCell.Y) % 2 == 1)
//                hilightrowOffset = Tile.OddRowXOffset;

//            BFGame.SpriteBatch.Draw(
//                            hlt,
//                            Camera.WorldToScreen(
//                            new Vector2(
//                                (mapCell.X * Tile.TileStepX) + hilightrowOffset,
//                                (mapCell.Y + 2) * Tile.TileStepY)),
//                            new Rectangle(0, 0, 64, 32),
//                            Color.White * 0.4f,
//                            0.0f,
//                            Vector2.Zero,
//                            1.0f,
//                            SpriteEffects.None,
//                            0.0f);
//        }


//        public override void Initialize() {
//            Console.WriteLine("Map manager initialized");

//        }

//        public void InsertCharacterToMap(Character c) {
//            c.UpdateTileLocation(myMap);
//            myMap.CharactersInMap.Add(c);
//        }

//        public void UpdateCharacterCellLocation(Character c) {
//            c.UpdateTileLocation(myMap);
//        }
//    }
//}

